<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/4/20
 * Time: 10:04
 */

namespace app\adminapiv3\service;


use app\common\service\HostNormalRuleGroupRelation;
use app\common\service\HostNormalRuleRelation;
use app\common\service\HostStatus;

class DefaultSetting extends Base
{
    /**
     * @name 恢复默认设置
     * @Author wx
     * @date 2019/8/16 13:19
     */
    function defaultSetting($host_id)
    {
        $this->checkOptionHost($host_id);

        $hostInfo = db('host')->field('id')->where('id', $host_id)->find();

        if (empty($hostInfo)) {
            $this->setError($this->CODE_FAIL, '未找到该主机');
            return false;
        }

        //1. 默认规则组
        $ruleGroupServer = new HostNormalRuleGroupRelation();
        $ruleGroupServer->clear($host_id);
        $ruleGroupServer->init($host_id);

        //2. 默认规则
        $ruleServer = new HostNormalRuleRelation();
        $ruleServer->clear($host_id);
        $ruleServer->init($host_id);


        //3. 修改主动防御配置
        $hostStatus = [
            'auto_defense' => 1,//主动防御
            'shell_defense' => 1,//脚本防御
            'shell_defense_handle' => 1,//脚本防御处理模式
            'shell_defense_level' => 2,//脚本防御级别
            'illegal_modify' => 1,//防篡改
            'file_safe' => 1,//畸形文件保护
            'empowerment' => 1,//提权
        ];

        $hostWhere = ['host_id' => $host_id];
        $hostStatusServer = new HostStatus();
        $hostStatusServer->modify($hostWhere, $hostStatus);

        //4. 修改wipf网络防御配置
        $ipsConfig = [
            'type' => 1,
            'black' => 0,
            'firewall' => 1,
            'protect_ip' => '',
            'device_ip' => '',
            'status' => '1',
        ];
        $ipsConfigServer = new \app\common\service\IpsConfig();
        $ipsConfigServer->modify($hostWhere, $ipsConfig);

        return true;
    }



    /**
     * @name 重启设备
     * @Author wx
     * @date 2019/8/16 13:20
     */
    function restartDevice()
    {
        //发送一条指令给中间件
        return true;
    }

}